package com.alipay.mapper;

import com.alipay.exception.ExpireException;
import com.alipay.exception.OverBalanceException;
import com.alipay.model.entity.RedBagEntity;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Jun
 * @date 2019/3/23
 */
@Repository
public interface RedBagMapper {

    /**
     * 红包入库
     * @param redBagEntity
     */
    int insert(RedBagEntity redBagEntity);

    /**
     * 获取红包信息
     * @param redBagNo
     * @return
     */
    RedBagEntity getRedBagEntity(String redBagNo);

    /**
     * 更改红包状态
     * @param redBagNo
     * @param status
     * @return
     */
    int updateStatus(String redBagNo, Byte status);

    /**
     * 更改红包退款状态
     * @param redBagNo
     * @param status
     * @return
     */
    int updateRefundStatus(String redBagNo, Byte status);

    /**
     * 更改红包状态, 乐观锁
     * @param redBagNo
     * @param oldStatus
     * @param newStatus
     * @param expireTime
     * @return
     */
    boolean updateStatusAndExpireTime(String redBagNo, Byte oldStatus, Byte newStatus, Date expireTime);

    /**
     * 查询红包状态
     * @param redBagNo
     * @return
     */
    Byte queryStatus(String redBagNo);

    /**
     * 更改红包状态, 更改时判断是否过期，判断是否超过红包总金额
     * @param redBagNo
     * @param value
     * @return
     * @throws ExpireException
     * @throws OverBalanceException
     */
    boolean incrConsumeAmount(String redBagNo, BigDecimal value) throws ExpireException, OverBalanceException;

    /**
     * 获取退款失败的红包记录
     * @param redBagEntity
     * @param limit
     * @return
     */
    List<RedBagEntity> queryRedBagTransInfo(RedBagEntity redBagEntity, Integer limit);

    /**
     * 获取退款失败的红包记录
     * @param redBagEntity
     * @param lastId
     * @param limit
     * @return
     */
    List<RedBagEntity> queryRedBagTransInfo(RedBagEntity redBagEntity, Long lastId, Integer limit);
}
